var gl_vue_vm_list_comp_html = $('#vue_vm_list_elderComp').html();
var pageParam = null;

$(function() {
	$('#vue_vm_list div').hide();
	$('#vue_vm_list_elderComp div').hide();
	
	var pageParamStr = $.url().param('pageParam');
	pageParam = JSON.parse(pageParamStr);
	var loginedUser = getLoginedUser();
	pageParam.createId = loginedUser.staffId;
	pageParam.createName = loginedUser.staffName;
	
	showParamInfo(pageParam);
	showParamInfo_comp(pageParam);
	
	if(load_roomAsset_by_roomId) {
		load_roomAsset_by_roomId(pageParam.roomId);
	}
});

function showParamInfo(pageParam) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	$('#vue_vm_list').html(gl_vue_vm_list_html);
	
	new Vue({
		el: '#vue_vm_list',
		data: {
			todos: [pageParam]
		}
	});
	
	$('#vue_vm_list div').show();
}

function showParamInfo_comp(pageParam) {
	if($('#vue_vm_list_elderComp').length==0) {return;}
	$('#vue_vm_list_elderComp div').hide();
	$('#vue_vm_list_elderComp').html(gl_vue_vm_list_comp_html);
	
	new Vue({
		el: '#vue_vm_list_elderComp',
		data: {
			todos: pageParam.roomAssetCompArray
		}
	});
	
	$('#vue_vm_list_elderComp div').show();
}

function goPage_2() {
	if(isEmpty(pageParam.elderId)) {
		alert('请选择一个长者');
		return;
	}
	
	pageParam.roomAssetCompArray = [];
	for(var i=0; i<roomAssetDamagedArray.length; i++) {
		if(roomAssetDamagedArray[i].compQuantity>0) {
			if(roomAssetDamagedArray[i].compQuantity>roomAssetDamagedArray[i].quantity) {
				alert('赔偿数不能超过此资产的总数');
				return;
			}
			
			var roomAssetComp = {};
			roomAssetComp.elderId = roomAssetDamagedArray[i].elderId;
			roomAssetComp.roomId = roomAssetDamagedArray[i].roomId;
			roomAssetComp.roomAssetId = roomAssetDamagedArray[i].roomAssetId;
			roomAssetComp.assetId = roomAssetDamagedArray[i].assetId;
			roomAssetComp.assetName = roomAssetDamagedArray[i].assetName;
			roomAssetComp.price = roomAssetDamagedArray[i].price;
			roomAssetComp.compQuantity = roomAssetDamagedArray[i].compQuantity;
			roomAssetComp.compStatus = roomAssetDamagedArray[i].compStatus;
			roomAssetComp.subjectRoomId = getLoginedUser()? getLoginedUser().subjectRoomId: '';
			pageParam.roomAssetCompArray.push(roomAssetComp);
		}else if(roomAssetDamagedArray[i].compQuantity<0) {
			alert('不支持输入负数');
			return;
		}
	}
	
	var url = '6-2-9cybg-2.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
	window.open(url);
}

function deleteBatch() {
	deleteBatch_basic(path+'/lease/deleteBatch');
}
